package com.ruoyi.doudian.controller;

import com.github.pagehelper.PageHelper;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.doudian.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

/**
 * @author X
 * @version 1.0
 * @ClassName GoodsController
 * @description
 * @date 2020/11/2
 **/
@RestController
@RequestMapping("/goods")
public class GoodsController {

    @Autowired
    private GoodsService goodsService;

    /***
     * 获取店铺商品列表
     * @return
     */
    @GetMapping("/getGoodsList/{page}/{size}")
    public AjaxResult getGoodsList(@PathVariable int page,
                                   @PathVariable int size) throws Exception {
        String result = goodsService.getGoodsList(page, size);
        if (null == result) {
            AjaxResult.error("请重新授权");
        }
        return AjaxResult.success(result);
    }

    /***
     * 获取商品信息
     * @return
     */
    @GetMapping("/getGoodsByProductId/{productId}")
    public AjaxResult getGoodsByProductId(@PathVariable String productId) throws Exception {
        String result = goodsService.getGoodsByProductId(productId);
        if (null == result) {
            AjaxResult.error("请重新授权");
        }
        return AjaxResult.success(result);
    }
}
